﻿@model Management.Areas.Control.Models.LoginViewModel

@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>登录</title>
    @Styles.Render("~/Content/Control")
    @Scripts.Render("~/bundles/modernizr")
    @Scripts.Render("~/bundles/Control")
    @Scripts.Render("~/bundles/jquery")
    @Scripts.Render("~/bundles/jqueryval")
</head>
<body>
    @*@Scripts.Render("~/Content/layer")*@
    <div class="loginform">
        <div class="form-horizontal">
            <h2 class="text-primary">英利生产管理系统登录</h2>
            @using (Html.BeginForm())
            {
                @Html.AntiForgeryToken()
                @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                <div class="form-group form-group-lg">
                    @Html.EditorFor(model => model.Accounts, new { htmlAttributes = new { @class = "form-control", placeholder = "帐号" } })
                    @Html.ValidationMessageFor(model => model.Accounts, "", new { @class = "text-danger" })
                </div>
                <div class="form-group form-group-lg">
                    @Html.EditorFor(model => model.Password, new { htmlAttributes = new { @class = "form-control", placeholder = "密码" } })
                    @Html.ValidationMessageFor(model => model.Password, "", new { @class = "text-danger" })
                </div>
                <div class="form-group form-group-lg" style="display:none" id="div_valiCode">
                    <input type="text" style="display:none" value="" name="cnt" id="cnt"/>
                    @*<input name="code" id="valiCode" type="text" class="form-control" placeholder="验证码"/>*@
                    @Html.EditorFor(model => model.valicode, new { htmlAttributes = new { @class = "form-control", placeholder = "验证码" } })
                    @Html.ValidationMessageFor(model => model.valicode, "", new { @class = "text-danger" })
                    <p></p>
                    <img id="img_valiCode" style="cursor: pointer;" src="CetValidateCode" alt="验证码" />
                </div>
                <div class="form-group form-group-lg">
                    <a href="javascript:void(0)" data-toggle="modal" data-target="#ForgetModel">忘记密码</a>
                    <input type="submit" id="login" value="登录" class="btn btn-default pull-right" />
                </div>
            }
        </div>
    </div>
    <div class="modal fade" id="ForgetModel" tabindex="-1" role="dialog" aria-labelledby="ForgetModelLabel" aria-hidden="true" >
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                    <h4 class="modal-title" id="ModalLabel">忘记密码</h4>
                </div>
                <div class="modal-body">
                    <div class="alert-danger" role="alert" id="f_message" style="display:none"><span class="glyphicon glyphicon-remove" id="f_msg"></span></div>
                    <table border="0" width="500">
                        <tr>
                            <td>
                                <input id="email" placeholder="您的邮箱" class="form-control" style="margin-left: 68px" />
                                <p></p>
                                <input id="fCode" placeholder="验证码" class="form-control" style="margin-left: 68px"/>
                                <p></p>
                                <img id="img_fvaliCode" style="cursor: pointer; margin-left: 68px" src="CetValidateCode" alt="验证码" />
                            </td>
                        </tr>
                    </table>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button type="button" class="btn btn-primary" id="f_save">提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

<script src="~/Content/layer/layer.js"></script>
<script src="~/Scripts/CookieOperation.js"></script>
<script type="text/javascript">
    var msg = "登陆超时或已退出登录";
</script>
@if (Session["AdminID"] != null && Request.Cookies["unauthorized"] != null)
{
    <script type="text/javascript">
        setTimeout('location.href = "@Url.Action("Index", "Home")"', 2000);
        msg = "权限不足";
    </script>
}
<script type="text/javascript">
    localStorage.flag = 1;//首页用
	
    if (!getCookie("logincnt"))
    {
        //localStorage.cnt = 0;
		setCookie("logincnt", 0);
    }
    if (getCookie("logincnt") > 2)
    {
        $('#div_valiCode').show();
        document.getElementById('cnt').value = getCookie("logincnt");
    }
    $('#login').click(function () {
        setCookie("cnt", parseInt(getCookie("cnt")) + 1);
		if (getCookie("cnt") > 2)
		{
			$('#div_valiCode').show();
			document.getElementById('cnt').value = getCookie("logincnt");
		}
    });
    if (getCookie("unauthorized"))
    {
        layer.msg(msg, { icon: 4 });
        delCookie("unauthorized");
    }
    if (getCookie("ForcedOff"))
    {
        msg = "您已经被迫下线,新的登陆IP为";
        var ip = getCookie("ForcedOff");
        layer.msg(msg + ip, { icon: 0 });
        delCookie("ForcedOff");
    }
    $(function () {
        $("#img_valiCode").bind("click", function () {
            this.src = "CetValidateCode?time=" + (new Date()).getTime();
        });
        $("#img_fvaliCode").bind("click", function () {
            this.src = "CetValidateCode?time=" + (new Date()).getTime();
        });
    });

    $("#f_save").click(function () {
        var email = document.getElementById("email").value;
        var f_code = document.getElementById("fCode").value;
        layer.load();
        if (typeof (email) == 'undefined' || typeof (f_code) == 'undefined')
        {
            layer.alert("邮箱和验证码均不可为空", { icon: 0 });
        }
        else
        {            
            $.ajax({
                url: "ForgetPwd1",
                data: { email: email, code: f_code },
                type: "get",
                success: function (json) {
                    layer.closeAll('loading');
                    if (json.Code == 0)
                    {
                        $("#f_msg").html(json.Message);
                        $("#f_message").show();
                        layer.alert(json.Message);                        
                    }
                    else
                    {                        
                        $("#ForgetModel").toggle();
                        layer.prompt({ title: '输入您收到的识别码，并确认', formType: 0 }, function (pass, index) {
                            layer.load();
                            layer.close(index);
                            $.ajax({
                                url: "ForgetPwd2",
                                data: { f_Validate: pass },
                                type: "get",
                                success: function (json2) {
                                    layer.closeAll('loading');
                                    if(json2.Code == 0)
                                    {                                        
                                        layer.alert(json2.Message);
                                    }
                                    else
                                    {
                                        layer.prompt({ title: '请输入您的新登录密码，并确认', formType: 1 }, function (pwd, second) {
                                            layer.load();
                                            $.ajax({
                                                url: "ForgetPwd3",
                                                data: { email: email, newPwd: pwd, flag: true },
                                                type: "post",
                                                success: function (json3) {
                                                    layer.closeAll('loading');
                                                    layer.close(second);
                                                    layer.alert(json3.Message);
                                                }
                                            })
                                        })
                                    }
                                }
                            })
                        })
                    }
                    
                },
                error: function () {
                    layer.msg("网络错误", {icon: 2})
                }
            })
        }
    })
</script>